﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 算法入门.Utils
{
    public static class BitOperatorHelp
    {
        /// <summary>
        /// 得到整数的32位二进制字符串
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetBitStr(int input)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 31; i >= 0; i--)
            {
                //注意:(1 << i) & input    input & (1 << i)    这两种方式都可以，位置没有关系
                sb.Append((input & (1 << i)) == 0 ? "0" : "1");
            }

            return sb.ToString();
        }
    }
}
